<?php
class Login extends CI_Controller{
		
	public function index(){
		if($this->User_model->is_logged_in() == FALSE){
			$this->load->view('login/index');
		}
		else{
			if($this->session->userdata('preUrl')){
				redirect( $this->session->userdata('preUrl'));
			}
			else 
				redirect('dashboard');
		}
	}
	
	public function check_login(){
		if($this->User_model->validate_login()){
			if($this->session->userdata('preUrl')){
				$preUrl = $this->session->userdata('preUrl');
				$this->session->unset_userdata('preUrl');
				redirect( $preUrl);
			}
			else 
				redirect('dashboard');
		}else {
			redirect('');
		}
	}
	
	public function logout(){
		$this->User_model->changeIsLogged($this->session->userdata('admin'),0);
		$this->session->unset_userdata('admin');
		$this->session->unset_userdata('admin_name');
		
		redirect('');
	}
	
	public function test(){
		print_r($_SERVER);
	}
	
	
	/*
	public function register(){
		$this->User_model->register();
	}
	*/
}